#!/bin/bash

set -e -o pipefail

source $(dirname $0)/version
DIST=$(realpath "$(dirname $0)/../dist/artifacts")
if [ ! -d "${DIST}" ]; then
  echo "Missing artifacts directory '${DIST}', have you run 'make build' (and then 'make package') ?" >&2
  exit 1
fi
export ARCH COMMIT DIST REPO TAG VERSION

# ---

set -x
tar xzf ${DIST}/sonobuoy-results-amd64.tar.gz -C ${DIST}/../.
if [[ $(grep -E 'Status' ${DIST}/../sonobuoy-results-${ARCH}.txt | awk '{print $2}') != passed ]]; then
  exit 255
fi
